#ifndef __LINUX__AIO_H
#define __LINUX__AIO_H

#include <linux/uio.h>
#include <linux/fs2.h>
#include <linux/list.h>

#define KIOCB_SYNC_KEY		(~0U)

struct kiocb {
	// struct list_head	ki_run_list;
	unsigned long		ki_flags;
	int			ki_users;
	unsigned		ki_key;		/* id of this request */

	struct file		*ki_filp;
	// struct kioctx		*ki_ctx;	/* may be NULL for sync ops */
	// int			(*ki_cancel)(struct kiocb *, struct io_event *);
	ssize_t			(*ki_retry)(struct kiocb *);
	void			(*ki_dtor)(struct kiocb *);

	union {
		void		*user;
		struct task_struct	*tsk;
	} ki_obj;

	// __u64			ki_user_data;	/* user's data for completion */
	// wait_queue_t		ki_wait;
	loff_t			ki_pos;

	// void			*private;
	// /* State that we remember to be able to restart/retry  */
	// unsigned short		ki_opcode;
	// size_t			ki_nbytes; 	/* copy of iocb->aio_nbytes */
	// char			*ki_buf;	/* remaining iocb->aio_buf */
	size_t			ki_left; 	/* remaining bytes */
	// struct iovec		ki_inline_vec;	/* inline vector */
 	// struct iovec		*ki_iovec;
 	// unsigned long		ki_nr_segs;
 	// unsigned long		ki_cur_seg;

	// struct list_head	ki_list;	/* the aio core uses this
						//  * for cancellation */

	/*
	 * If the aio_resfd field of the userspace iocb is not zero,
	 * this is the underlying eventfd context to deliver events to.
	 */
	// struct eventfd_ctx	*ki_eventfd;
};

#define init_sync_kiocb(x, filp)			\
	do {						\
		struct task_struct *tsk = current;	\
		(x)->ki_flags = 0;			\
		(x)->ki_users = 1;			\
		(x)->ki_key = KIOCB_SYNC_KEY;		\
		(x)->ki_filp = (filp);			\
		(x)->ki_retry = NULL;			\
		(x)->ki_dtor = NULL;			\
		(x)->ki_obj.tsk = tsk;			\
	} while (0)

#endif
